#ifndef _PAGING_H
#define _PAGING_H

/* Setting up page directory */
unsigned long *page_directory = (unsigned long *)0x9C000;

/* Setting up paging table, right after the page directory */
unsigned long *page_table = (unsigned long *)0x9D000;

/* Holds the physical address of where a page is */
unsigned long address = 0;
unsigned i = 0;

/* Map the first 4MB of memory */
for (; i<1024; i++) {
	/*attribute set to: supervisor level, read/write, present (011 in binary) */
	page_table[i] = address | 3; 
	/* 4096 = 4kb */
	address = address + 4096;
};

/* Fill the first entry of the page directory */
/* attribute set to: supervisor level, read/write, present(011 in binary) */
page_directory[0] = page_table;
page_directory[0] = page_directory[0] | 3;

for(i=1; i<1024; i++) {
	/* attribute set to: supervisor level, read/write, not present (010 in binary) */
	page_directory[i] = 0 | 2;
};


// write_cr3, read_cr3, write_cr0, and read_cr0 all come from the assembly functions
_write_cr3 (page_directory); // put that page directory address into CR3
_write_cr0 (_read_cr0() | 0x80000000); // set the paging bit in CR0 to 1

#endif
